package com.jrx.anytxn.customer.controller;


import com.alibaba.fastjson.JSON;
import com.jrx.anytxn.customer.constant.CustomerConstant;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerLimitFrozeResultReq;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerLimitFrozeBaseRes;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerLimitFrozeQueryRes;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerLimitFrozeFrozeReq;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerLimitFrozeRes;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerLimitFrozeUseRes;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerUseLimitFrozeFrozeReq;
import com.jrx.anytxn.customer.dto.customer.medical.CustomerLimitFrozeInfoReq;
import com.jrx.anytxn.customer.service.impl.ICmCustomerLimitFrozeServiceImpl;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 信用就医客户额度冻结、解冻处理的api接口
 *
 * @author user
 * @date 2022/08/12
 */
@Api(tags = "信用就医客户额度处理api接口")
@RestController
@RequestMapping(value = "/api/customer/medical")
public class CustomerLimitFreezeController {

    private static Logger logger = LoggerFactory.getLogger(CustomerLimitFreezeController.class);

    @Autowired
    private ICmCustomerLimitFrozeServiceImpl iCmCustomerLimitFrozeService;

    @ApiOperation(value = "客户额度冻结/解冻", notes = "客户额度冻结/解冻")
    @PostMapping(value = "/freezeOperate")
    public TxnRespResult<CustomerLimitFrozeRes> creditMedicalFreeze(@Valid @RequestBody CustomerLimitFrozeFrozeReq req) throws Exception {
        logger.info("冻结处理请求req：{}", JSON.toJSONString(req));
        //参数补充校验
        req.check();
        CustomerLimitFrozeRes customerLimitFrozeRes;
        if ((CustomerConstant.OPERATE_TYPE_F.equals(req.getOperateType()))) {
            //冻结操作
            customerLimitFrozeRes = iCmCustomerLimitFrozeService.creditMedicalFreeze(req);
        } else {
            //解冻冻操作
            customerLimitFrozeRes = iCmCustomerLimitFrozeService.creditMedicalUnfreeze(req);
        }
        TxnRespResult<CustomerLimitFrozeRes> result = new TxnRespResult<>();
        result.getSuccess(customerLimitFrozeRes);
        logger.info("客户额度冻结/解冻响应result：{}", JSON.toJSONString(result));
        return result;
    }


    @ApiOperation(value = "冻结、解冻结果查询", notes = "冻结、解冻结果查询")
    @PostMapping(value = "/freezeResultQuery")
    public TxnRespResult<CustomerLimitFrozeBaseRes> limitFreezeResultQuery(@Valid @RequestBody CustomerLimitFrozeResultReq queryReq) throws Exception {
        logger.info("冻结、解冻结果查询请求req：{}", JSON.toJSONString(queryReq));
        queryReq.check();
        TxnRespResult<CustomerLimitFrozeBaseRes> result = new TxnRespResult<>();
        CustomerLimitFrozeBaseRes customerLimitFrozeQueryRes = iCmCustomerLimitFrozeService.limitFreezeResultQuery(queryReq);
        result.getSuccess(customerLimitFrozeQueryRes);
        logger.info("冻结、解冻结果查询响应result：{}", JSON.toJSONString(result));
        return result;
    }

    @ApiOperation(value = "客户额度信息查询", notes = "客户额度信息查询")
    @PostMapping(value = "/limitInfos")
    public TxnRespResult<CustomerLimitFrozeQueryRes> customerLimitInfos(@Valid @RequestBody CustomerLimitFrozeInfoReq queryReq) throws Exception {
        logger.info("客户额度信息查询请求req：{}", JSON.toJSONString(queryReq));
        TxnRespResult<CustomerLimitFrozeQueryRes> result = new TxnRespResult<>();
        CustomerLimitFrozeQueryRes customerLimitFrozeQueryRes = iCmCustomerLimitFrozeService.limitFreezeInfoQuery(queryReq);
        result.getSuccess(customerLimitFrozeQueryRes);
        logger.info("客户额度信息查询响应result：{}", JSON.toJSONString(result));
        return result;
    }

    @ApiOperation(value = "客户冻结额度占用", notes = "客户冻结额度占用")
    @PostMapping(value = "/frozeLimitUse")
    public TxnRespResult<CustomerLimitFrozeUseRes> frozeLimitUse(@Valid @RequestBody CustomerUseLimitFrozeFrozeReq req) throws Exception {
        logger.info("客户冻结额度占用请求req：{}", JSON.toJSONString(req));
        req.check();
        TxnRespResult<CustomerLimitFrozeUseRes> result = new TxnRespResult<>();
        CustomerLimitFrozeUseRes customerLimitFrozeRes = iCmCustomerLimitFrozeService.creditMedicalUseFrozeLimit(req);
        result.getSuccess(customerLimitFrozeRes);
        logger.info("客户冻结额度占用响应result：{}", JSON.toJSONString(result));
        return result;
    }
}

